package com.shop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shop.entity.UmsAdmin;
import com.shop.service.UmsAdminService;
import com.shop.vo.ResultJson;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author lpx610
 * @since 2023-10-29
 */
@RestController
@RequestMapping("/umsAdmin")
public class UmsAdminController {
    @Resource
    private UmsAdminService adminService;

    @GetMapping("/list")
    public ResultJson<IPage<UmsAdmin>> list(Integer pageNo, Integer pageSize, String username, Integer order) {
        return ResultJson.success(adminService.list(pageNo, pageSize, username, order));
    }

    @GetMapping("/getById")
    public ResultJson<UmsAdmin> getById(String id) {
        return ResultJson.success(adminService.getById(id));
    }

    @PostMapping("/add")
    public ResultJson<Boolean> add(String username, String password, String phone, String email, Integer gender, MultipartFile file) {
        System.out.println(username);
        return ResultJson.success(adminService.add(username, password, phone, email, gender, file), "数据添加成功");
    }

    @PostMapping("/update")
    public ResultJson<Boolean> update(String id, String username, String phone, String email, Integer gender, MultipartFile file) {
        return ResultJson.success(adminService.update(id, username, phone, email, gender, file), "数据修改成功");
    }

    @GetMapping("/delete")
    public ResultJson<Boolean> delete(String id, Boolean active) {
        return ResultJson.success(adminService.delete(id, active), active ? "已成功启用": "已成功禁用");
    }
}
